package hz.mobileproject.pda.firesafety.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.caption.netmonitorlibrary.netStateLib.NetUtils;
import com.google.zxing.activity.CaptureActivity;
import com.youth.banner.Banner;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.util.Arrays;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.listener.GlideImageLoader;
import hz.mobileproject.pda.network.Constance;
import hz.mobileproject.pda.ui.base.BaseNetActivity;
import hz.mobileproject.pda.utils.CommonUtil;

@ContentView(R.layout.activity_fire_search)
public class  FireSearchActivity extends BaseNetActivity {
    @ViewInject(R.id.banner)
    private Banner _banner;

    //打开扫描界面请求码
    private int REQUEST_CODE = 0x01;
    //扫描成功返回码
    private int RESULT_OK = 0xA1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置图片加载器
        _banner.setImageLoader(new GlideImageLoader());
        //设置图片集合
        _banner.setImages(Arrays.asList(new Integer[]{R.drawable.anquan,R.drawable.tanhua}));
        //banner设置方法全部调用完毕时最后调用
        _banner.start();
    }


    @Event(value = {R.id.tv_start_inventory})
    private void viewOnClick(View v){
        switch (v.getId()){
            case R.id.tv_start_inventory:

//                if(Constance.isNeiMeng) {  //如果是演示版本则打开相机扫描
//                    //打开二维码扫描界面
//                    if(CommonUtil.isCameraCanUse()){
//                        Intent intent = new Intent(FireSearchActivity.this, CaptureActivity.class);
//                        startActivityForResult(intent, REQUEST_CODE);
//                    }else{
//                        Toast.makeText(this,"请打开此应用的摄像头权限！",Toast.LENGTH_SHORT).show();
//                    }
//                }else {
                    startActivity(new Intent(this,StartFireSatetyActivity.class));
//                }
                break;
        }
    }




    /**
     * 网络连接状态
     * @param type 网络状态
     */
    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {
        LogUtils.e("网络状态："+type.toString());
    }

    /**
     * 网络断开
     */
    @Override
    protected void onNetworkDisConnected() {
        LogUtils.e("网络断开");
    }



    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //扫描结果回调
        if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) { //RESULT_OK = -1
            Bundle bundle = data.getExtras();
            String scanResult = bundle.getString("qr_scan_result");

            if(scanResult.contains("P")) {
                //扫描的是民警的条形码
                Intent intent = new Intent(FireSearchActivity.this, StartFireSatetyActivity.class);
                intent.putExtra("police_tiaoma", scanResult);
                startActivity(intent);
            }else {
                ToastUtils.showLong("请先扫描民警条码");
            }

        }
    }
}
